#include <bits/stdc++.h>
#define int long long
using namespace std;

const int N = 1e5 + 5;

int d[N], v[N], a[N], p[N];

signed main()
{
    freopen("detect.in", "r", stdin);
    freopen("detect.out", "w", stdout);
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t;
    cin >> t;
    for (int K = 1; K <= t; K++)
    {
        int n, m, L, V, ans1 = 0, ans2 = 0;
        cin >> n >> m >> L >> V;
        for (int i = 1; i <= n; i++)
            cin >> d[i] >> v[i] >> a[i];
        for (int i = 1; i <= m; i++)
            cin >> p[i];
        /*for (int i = 1; i <= n; i++)
        {
            if (a[i] == 0)
            {
                if (v[i] > V)
                {
                    bool cnt = 0;
                    for (int j = 1; j <= m; j++)
                    {
                        
                        if (p[j] >= d[i])
                        {
                            cnt = 1;
                            vis[i][j] = 1;
                        }
                    }
                    ans1 += cnt;
                }  
            }
            else if (a[i] > 0)
            {
                double s = 0;
                if (v[i] < V) s = (V + v[i]) * (V - v[i]) / (2 * a[i]) * 1.00;
                d[i] += s;
                bool cnt = 0;
                for (int j = 1; j <= m; j++)
                {
                    if (p[j] > d[i])
                    {
                        cnt = 1;
                        vis[i][j] = 1;
                        //cout << i << " " << j << "\n";
                    }
                }
                ans1 += cnt;    
            }
            else
            {
                if (v[i] > V)
                {
                    double s = (V + v[i]) * (V - v[i]) / (2 * a[i]) * 1.00;
                    bool cnt = 0;
                    for (int j = 1; j <= m; j++)
                    {
                        if (p[j] >= d[i] && p[j] < d[i] + s)
                        {
                            cnt = 1;
                            vis[i][j] = 1;
                            //cout << i << " " << j << "\n";
                        }
                    }
                    ans1 += cnt;
                }
            }
        }*/
        if (a[1] == 0 && a[2] == 0 && a[3] == 0)
        {
            for (int i = 1; i <= n; i++)
            {
                if (v[i] > V)
                    for (int j = 1; j <= m; j++)
                        if (p[j] >= d[i])
                        {
                            ans1++;
                            break;
                        }
            }
            if (ans1 != 0) ans2 = m - 1;
            cout << ans1 << " " << ans2 << "\n";
            return 0;
        }
        //int len = st.size();
        //ans2 = m - len;
        //cout << ans1 << " " << ans2 << "\n";
        /*int maxn = 0;
        for (int i = 1; i <= m; i++)
        {
            int jsq = 0;
            for (int j = 1; j <= n; j++)
            {
                if (vis[j][i] == 1) jsq++;
            }
            maxn = max(maxn, jsq);
        }
        ans2 = ans1 - maxn + 1;
        cout << ans1 << " " << m - ans2 << "\n";*/
    }
    return 0;
}